<?php
App::uses('AppController', 'Controller');

class FrontsController extends AppController {

	public $uses = array('Presentation','Preview','Upload');
	//var $name = 'Fronts';

	//function index() {
		//$this->Front->recursive = 0;
		//$this->set('fronts', $this->paginate());
	//}

	function indexAlumno() {
		date_default_timezone_set('Chile/Continental');
		$fecha = date("Y-m-d");
		//$fecha = date("Y-m-d")." 00:00:00";
		//$this->set('fecha',$fecha1);
		//print($fecha1);
		$filtro=$this->Presentation->find('first',array('conditions'=>array('Presentation.startdate <=' => $fecha,'Presentation.enddate >=' => $fecha)));	
		$this->set('presentation',$filtro);		
		if(!empty($filtro)){
			$start=	$filtro['Presentation']['startdate'];
			$end= $filtro['Presentation']['enddate'];
			$presentation_id= $filtro['Presentation']['id'];
			$user = $this->Session->read('Auth.User');
			$user_id=$user['id'];
			//print($user_id);
			
			//$consulta="SELECT previews.id as preview_id, uploads.id as upload_id FROM previews,uploads where previews.upload_id = uploads.id and uploads.user_id='$user_id' and modified >='$start 00:00:00' and modified<='$end 23:59:59'";
			$consulta="SELECT previews.id as preview_id, previews.upload_id as upload_id FROM previews where user_id=$user_id and presentation_id=$presentation_id";
			//print($consulta);
			$ids=$this->Preview->query($consulta);
			$this->set('ids',$ids);
			//print_r($ids);
		}
		//$this->Front->recursive = 0;
		//$this->set('fronts', $this->paginate());
	}

	//function indexAdmin() {
		//$this->Front->recursive = 0;
		//$this->set('fronts', $this->paginate());
	//}

	function indexEvaluador() {
		date_default_timezone_set('Chile/Continental');
		$fecha=Date('Y-m-d', strtotime("-1 week"));
		//$fecha = date("Y-m-d")." 00:00:00";
		//$this->set('fecha',$fecha1);
		//print($fecha1);
		$filtro=$this->Presentation->find('first',array('conditions'=>array('Presentation.startdate <=' => $fecha,'Presentation.enddate >=' => $fecha)));	
		$this->set('presentation',$filtro);		
		if(!empty($filtro)){
			$start=	$filtro['Presentation']['startdate'];
			$end= $filtro['Presentation']['enddate'];
			$user = $this->Session->read('Auth.User');
			$user_id=$user['id'];
			//print($user_id);
			
			$consulta="SELECT previews.id as preview_id, uploads.id as upload_id FROM previews,uploads where previews.upload_id = uploads.id and uploads.user_id='$user_id' and modified >='$start 00:00:00' and modified<='$end 23:59:59'";
			//print($consulta);
			$ids=$this->Preview->query($consulta);
			$this->set('ids',$ids);
			//print_r($ids);
		}
		//$this->Front->recursive = 0;
		//$this->set('fronts', $this->paginate());
	}
	
	function addPreview($id)
	{
		//echo "<script>"."localStorage.setItem('idPresentation',$id);"."</script>";
		Cache::write("presentation_id",$id);
		Cache::write("anterior_page",$this->referer());
		//$this->set('idPresentation',$id);
		$this->redirect("/previews/add");
	}


}
?>
